import PIL.Image as Image


def transparent_back(img):
    """以图片左上角的点的颜色为透明背景"""
    img = img.convert('RGBA')
    L, H = img.size
    color_0 = img.getpixel((0, 0))
    for h in range(H):
        for l in range(L):
            dot = (l, h)
            color_1 = img.getpixel(dot)
            if color_1 == color_0:
                color_1 = color_1[:-1] + (0,)
                img.putpixel(dot, color_1)
    return img


# img = Image.open('images/enemy11_level1.png')
img = Image.open('images/enemy_level2.png')
img = transparent_back(img)
# ~ 如果不想覆盖原图就改名
img.save('images/enemy_level2.png')
